package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//注意这里service导包为org.apache.dubbo.config.annotation.Service;
@Service
@Transactional
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {

    @Override
    public boolean deleteById(Long id) {
        boolean b = this.removeById(id);
        return b;
    }

    @Override
    public List<CheckItem> findAll() {
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("delete_flag",0);
        return this.list(queryWrapper);
    }

    @Override
    public PageResult findByPage(QueryPageBean pageBean) {
        Page page = new Page(pageBean.getCurrentPage(),pageBean.getPageSize());
        IPage<CheckItem> result = this.page(page);
        System.out.println("****************************");
        System.out.println("=============总数"+result.getTotal());
        return new PageResult(result.getTotal(),result.getRecords());
    }

    @Override
    public List<CheckItem> findByGroupId(Long id) {
        return this.baseMapper.selectByGroupId(id);
    }
}